//
//  hvSimpleCalloutAnnotationView.m
//  CustomMapCalloutAnnotation
//
//  Created by moon on 14-5-7.
//  Copyright (c) 2014年 hv. All rights reserved.
//

#import "hvSimpleCalloutAnnotationView.h"

@implementation hvSimpleCalloutAnnotationView

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
	if (self=[super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
		self.pinColor = MKPinAnnotationColorRed;
		self.layer.borderColor = [UIColor redColor].CGColor;
		self.layer.borderWidth = 1;
		self.contentView.bounds = CGRectMake(0, 0, 80, 40);
		self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 12)];
		self.titleLabel.font = [UIFont systemFontOfSize:12];
		self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
		self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 14, 40, 12)];
		self.detailLabel.font = [UIFont systemFontOfSize:12];
		self.detailLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
		self.button = [UIButton buttonWithType:UIButtonTypeInfoDark];
		self.button.frame = CGRectMake(45, 5, 30, 30);
		self.button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
		[self.contentView addSubview:self.titleLabel];
		[self.contentView addSubview:self.detailLabel];
		[self.button addTarget:self action:@selector(buttonDidTap:) forControlEvents:UIControlEventTouchUpInside];
		[self.contentView addSubview:self.button];
	}
	return self;
}
- (void)buttonDidTap:(id)sender{
	CGRect rect = self.contentView.bounds;
	rect.size.width = rect.size.width==80?4000:80;
	rect.size.height = rect.size.height==40?80:40;
	[self.calloutView setContentSize:rect.size withAnimated:YES];
}

- (void)setAnnotation:(id<MKAnnotation>)annotation{
	[super setAnnotation:annotation];
	self.titleLabel.text = [annotation title];
	self.detailLabel.text = [annotation subtitle];
}
@end
